//用服务器请求过来的数据render表单

async function head() {
    const res = await indexAxios('userinfo')
    const { data: { data: { email, nickname, user_pic, id, username } } } = res

    $('input[placeholder="请输入原账号"]').val(username)
    $('input[placeholder="请输入昵称"]').val(nickname)
    $('input[placeholder="请输入邮箱"]').val(email)
    $('.layui-card input[name=id]').val(id)
}
head()

//修改账号信息
$('.layui-card-body .layui-form').on('submit', async function (e) {

    const obj = {
        nickname: $('.layui-card input[name=nickname]').val(),
        email: $('.layui-card input[name=email]').val(),
        id: $('.layui-card input[name=id]').val()
    }
    console.log(strFormat(obj));

    e.preventDefault()
    const res = await userInfoAxios('userinfo', strFormat(obj))
    const { data: { status } } = res
    //如果修改成功，改变父亲页面的的username
    if (status === 0) {
        window.parent.headPic()
    }
})


//点击重置按钮浏览器 表单重新render
$('.layui-btn-primary').on('click', function (e) {
    // console.log('click');
    e.preventDefault()
    head()
})